package com.dk.controller;

import com.dk.pojo.TabCategory;
import com.dk.pojo.TabRoute;
import com.dk.pojo.TabSeller;
import com.dk.service.TabCategoryService;
import com.dk.service.TabRouteService;
import com.dk.service.TabSellService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("tabRoute")
public class TabRouteController {
    @Autowired
    private TabRouteService tabRouteService;

    @Autowired
    private TabSellService tabSellService;

    @Autowired
    private TabCategoryService tabCategoryService;

    @RequestMapping("toShow")
    public String toShow(){
        return "tabRoute/show";
    }
    @RequestMapping("getInfo")
    @ResponseBody
    public List<TabRoute> getInfo(String rname,Model model){
        List<TabRoute> result = tabRouteService.getInfo(rname);
        List<TabSeller> list = tabSellService.getInfoSell();
        model.addAttribute("list",list);
        return result;
    }
    @RequestMapping("toAdd")
    public String toAdd(){
        return "tabRoute/add";
    }
    @RequestMapping("increase")
    @ResponseBody
    public boolean insertInfo(TabRoute tabRoute){
        return tabRouteService.insert(tabRoute) > 0;
    }
    @RequestMapping("toUpdate/{id}")
    public String toUpdate(@PathVariable("id")Integer cid, Model model){
        TabRoute tabRoute = tabRouteService.selectById(cid);
        model.addAttribute("tabRoute",tabRoute);
        return "tabRoute/update";
    }
    @RequestMapping("updateInfo")
    @ResponseBody
    public boolean updateInfo(TabRoute tabRoute){
        return tabRouteService.updateInfo(tabRoute) > 0;
    }
    @RequestMapping("deleteById")
    @ResponseBody
    public boolean deleteById(Integer rid){
        return tabRouteService.deleteById(rid) > 0;
    }
    @RequestMapping("getBySname/{sid}")
    @ResponseBody
    public TabSeller selectByName(@PathVariable("sid")Integer sid) {
        TabSeller result = tabSellService.selectById(sid);
        return result;
    }
    @RequestMapping("getByCname/{cid}")
    @ResponseBody
    public TabCategory selectByCame(@PathVariable("cid")Integer cid) {
        TabCategory result = tabCategoryService.selectById(cid);
        return result;
    }
}
